package com.ruoyi.project.report.revenue.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.report.car.domain.CarReport;
import com.ruoyi.project.report.revenue.domain.Revenue;
import com.ruoyi.project.report.revenue.service.IRevenueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * 营收统计报表Controller
 *
 * @author admin
 * @date 2021-01-19
 */
@Controller
@RequestMapping("/report/revenue")
public class RevenueController extends BaseController {
    private String prefix = "/report/revenue";

    @Autowired
    private IRevenueService revenueService;

    @RequiresPermissions("report:revenue:view")
    @GetMapping()
    public String revenue()
    {
        return prefix + "/revenue_report";
    }

    /**
     * 查询营收统计报表列表
     */
    @RequiresPermissions("report:revenue:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam(value = "startDate") String startDate,
                              @RequestParam(value = "endDate") String endDate,
                              @RequestParam(value = "dateFlag") int dateFlag)
    {
        startPage();
        List<Revenue> list = revenueService.selectRevenueByDate(startDate, endDate, dateFlag);

        return getDataTable(list);
    }

    /**
     * 导出营收统计报表
     */
    @RequiresPermissions("report:revenue:export")
    @Log(title = "营收统计报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam(value = "startDate") String startDate,
                             @RequestParam(value = "endDate") String endDate,
                             @RequestParam(value = "dateFlag") int dateFlag)
    {
        List<Revenue> list = revenueService.selectRevenueByDate(startDate, endDate, dateFlag);
        ExcelUtil<Revenue> util = new ExcelUtil<Revenue>(Revenue.class);
        return util.exportExcel(list, "营收统计报表数据");
    }
}
